import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';
import P02 from './P02';
import P04 from './P04';
import nodejs from '@feidao/web/atom/nodejs/msg/nodejs';
import server_render from '../atom/server-render';

import P10 from './P10';
import '@feidao/widgets/w-000010';

export default async function (fd: IFeidaoAiNodejsComponent, ...args: any[]) {
	const exam_id = fd.data.default_exam;

	const param = {
		criteria: { exam_id },
		page_size: 20,
		page_no: 1,
		asc: ['teacher_no']
	};
	const res = await nodejs('flippedclass', 'usable-exam-teacher-find', param);
	console.warn('................... exam_id .................', exam_id, res);

	if (res.count === 0) {
		server_render(fd.data.node, 'P02', P02, []);
		server_render(fd.data.node, 'P04', P04, []);
	} else {
		server_render(fd.data.node, 'P02', P02, res.dataArray);
		server_render(fd.data.node, 'P10', P10, { count: res.count, page_no: 1 });
	}
}